package com.cloudcc.mobile.view.activity;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cloudcc.cloudframe.util.DensityUtils;
import com.cloudcc.cloudframe.util.StringUtils;
import com.cloudcc.mobile.AppContext;
import com.cloudcc.mobile.R;
import com.cloudcc.mobile.adapter.ChatIndexAdapter;
import com.cloudcc.mobile.adapter.ChatIndexAdapter.OnItemListener;
import com.cloudcc.mobile.db.ChatMessageDB;
import com.cloudcc.mobile.entity.FavoriteFeed;
import com.cloudcc.mobile.entity.FeedFile;
import com.cloudcc.mobile.entity.MyChatter;
import com.cloudcc.mobile.entity.MyChatterMessage;
import com.cloudcc.mobile.entity.OptionUser;
import com.cloudcc.mobile.entity.PraiseFeed;
import com.cloudcc.mobile.entity.addmicropost.Polls;
import com.cloudcc.mobile.entity.chatter.ChatterParamData;
import com.cloudcc.mobile.entity.comment.Comments;
import com.cloudcc.mobile.entity.comment.CommentsFile;
import com.cloudcc.mobile.entity.handle.PraiseFeedInfo;
import com.cloudcc.mobile.entity.handle.RemoveMicroPost;
import com.cloudcc.mobile.manager.RunTimeManager;
import com.cloudcc.mobile.manager.UserManager;
import com.cloudcc.mobile.parser.HandleParser;
import com.cloudcc.mobile.parser.MyChatterParser;
import com.cloudcc.mobile.parser.ReturnCodeParser;
import com.cloudcc.mobile.service.MyChatterService;
import com.cloudcc.mobile.util.Json;
import com.cloudcc.mobile.util.LoadingUtils;
import com.cloudcc.mobile.util.NetWork;
import com.cloudcc.mobile.util.NotificationUtils;
import com.cloudcc.mobile.util.Tools;
import com.cloudcc.mobile.util.UrlTools;
import com.cloudcc.mobile.view.base.BaseActivity;
import com.cloudcc.mobile.view.dynamic.DynamicActivity;
import com.cloudcc.mobile.view.login.LoginNewActivity;
import com.cloudcc.mobile.weight.CustomListView;
import com.cloudcc.mobile.weight.CustomListView.OnLoadMoreListener;
import com.cloudcc.mobile.weight.CustomListView.OnRefreshListener;
import com.cloudcc.mobile.weight.LoadingView;
import com.lidroid.xutils.DbUtils;
import com.lidroid.xutils.db.sqlite.Selector;
import com.lidroid.xutils.exception.DbException;

import org.apache.http.NameValuePair;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import java.util.ArrayList;
import java.util.List;

/**
 * 关于我
 * 
 * @author Administrator
 * 
 */
public class AboutMeActivty extends BaseActivity implements OnClickListener {
	private ImageView finish, no_wangluoo;
	private FrameLayout frame, framelayout;
	private RelativeLayout mmm;
	private TextView tvpinglunaqwqw;
	private List<MyChatter> total = new ArrayList<MyChatter>();
	private LoadingView loadingview;
	private CustomListView listview;
	private MyChatterService service;
	private ChatIndexAdapter adapter;
	private ChatterParamData chatterParamData;
	int skip = 0, count = 0, page = 1, xuanze, weizhi, praisenum;;
	private String jsonstring, weizhiid;
	private boolean isfavorited, ispraised;
	private Receiver receiver;
	private MyChatterMessage msg;
	private MyChatter myChatter;
	private float ux, dx;
	private ChatMessageDB db6;
	private String mEns = RunTimeManager.getInstance().getlanguage();
	@Override
	public void init(Bundle savedInstanceState) {
		super.init(savedInstanceState);
		try {
			setupView();
			setDbData();
			addListener();
		} catch (DbException e) {
			e.printStackTrace();
		}

	}

	@Override
	public int getLayoutId() {
		return R.layout.aboutme;
	}

	/**
	 * 滑动返回
	 */
	@Override
	public boolean dispatchTouchEvent(MotionEvent ev) {
		// 当按下时处理
		if (ev.getAction() == MotionEvent.ACTION_DOWN) {
			dx = ev.getX();
		} else if (ev.getAction() == MotionEvent.ACTION_UP) {// 松开处理
			ux = ev.getX();
			if ((int) (ux - dx) > DensityUtils.getScreenWidth(mContext) / 2
					&& ux > dx) {
				finish();
				// 设置切换动画，从右边进入，左边退出
				overridePendingTransition(R.anim.in_from_left,
						R.anim.out_to_right);
			}
		}
		return super.dispatchTouchEvent(ev);
	}

	private void setupView() throws DbException {
		/**
		 * 处理代码, 清空chat数量
		 */
		db6 = new ChatMessageDB(this, UserManager.getManager().getUser().userId
				+ "chat");
		db6.deleteChatMessageAll();
		NotificationUtils.clearNotification(this, 2004);
		Intent messageNum = new Intent(AppContext.MESSAGE_CHAT_NUM);
		this.sendBroadcast(messageNum);

		AppContext.QueryType = "mobileMe";
		finish = (ImageView) findViewById(R.id.re);
		finish.setOnClickListener(this);

		frame = (FrameLayout) findViewById(R.id.indexrame);
		framelayout = (FrameLayout) findViewById(R.id.fragment);
		no_wangluoo = (ImageView) findViewById(R.id.no_wangluoo);
		mmm = (RelativeLayout) findViewById(R.id.introduction);
		tvpinglunaqwqw = (TextView) findViewById(R.id.tvpinglunaqwqw);
		loadingview = (LoadingView) findViewById(R.id.loa);
		listview = (CustomListView) findViewById(R.id.follower);
		listview.setDividerHeight(0);// 设置边框0无线
		listview.setCanRefresh(false);
		listview.setCanLoadMore(false);
		listview.setAutoLoadMore(false);
		service = new MyChatterService();
		adapter = new ChatIndexAdapter(this);
		setDbData();
		chatterParamData = new ChatterParamData();
		chatterParamData.setUserId(UserManager.getManager().getUser().userId);
		chatterParamData.setFeedSort(AppContext.feedSort);
		chatterParamData.setLimit(AppContext.limit);
		chatterParamData.setFeedId("");
		chatterParamData.setRecordId("");
		chatterParamData.setQueryType(AppContext.QueryType);
		count = 0;
		skip = count * 10;
		chatterParamData.setSkip(skip);
		jsonstring = Json.toJson(chatterParamData);
		new getChatterr().execute(jsonstring);
		receiver = new Receiver();
		IntentFilter filter = new IntentFilter();
		filter.addAction(AppContext.INDEXADAPTER_SHUAXIN);
		registerReceiver(receiver, filter);
	}

	private void setDbData() {
		DbUtils db = DbUtils.create(AboutMeActivty.this, UserManager
				.getManager().getUser().userId + AppContext.QueryType);
		try {
			if (db.tableIsExist(MyChatter.class)) {
				total = db.findAll(MyChatter.class);
				for (int i = 0; i < total.size(); i++) {
					if (db.tableIsExist(Comments.class)) {
						List<Comments> commentlist = db.findAll(Selector.from(
								Comments.class).where("parendId", "=",
								total.get(i).getId()));
						if (commentlist != null) {
							total.get(i).setComments(commentlist);
						}
					}
					if (db.tableIsExist(FeedFile.class)) {
						List<FeedFile> feedFiles = db.findAll(Selector.from(
								FeedFile.class).where("parendId", "=",
								total.get(i).getId()));
						if (feedFiles != null) {
							total.get(i).setFeedFile(feedFiles);
						}
					}
					if (db.tableIsExist(Polls.class)) {
						List<Polls> polls = db.findAll(Selector.from(
								Polls.class).where("parendId", "=",
								total.get(i).getId()));
						if (polls != null) {
							total.get(i).setPolls(polls);
						}
					}

				}
				adapter.changeData(total);
				listview.setAdapter(adapter);
				listview.setCanRefresh(true);
				listview.setCanLoadMore(true);
				listview.setAutoLoadMore(true);
			}

		} catch (DbException e) {
			Tools.handle(e);
		}
	}

	private void addListener() {
		tvpinglunaqwqw.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				mmm.setVisibility(View.GONE);
				framelayout.setVisibility(View.VISIBLE);
			}
		});

		frame.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (AppContext.QueryType.equals("mobileMe")) {
					listview.HideFooter();
					loadingview.setVisibility(View.VISIBLE);
					frame.setVisibility(View.GONE);
					framelayout.setVisibility(View.VISIBLE);
					chatterParamData = new ChatterParamData();
					chatterParamData.setUserId(UserManager.getManager()
							.getUser().userId);
					chatterParamData.setFeedSort(AppContext.feedSort);
					chatterParamData.setLimit(AppContext.limit);
					chatterParamData.setFeedId("");
					chatterParamData.setRecordId("");
					chatterParamData.setQueryType(AppContext.QueryType);
					page = 1;
					count = 0;
					skip = count * 10;
					chatterParamData.setSkip(skip);
					String a = Json.toJson(chatterParamData);
					new getChatterr().execute(a);
				}

			}
		});
		listview.setOnRefreshListener(new OnRefreshListener() {
			@Override
			public void onRefresh() {
				if (AppContext.QueryType.equals("mobileMe")) {
					chatterParamData = new ChatterParamData();
					chatterParamData.setUserId(UserManager.getManager()
							.getUser().userId);
					chatterParamData.setFeedSort(AppContext.feedSort);
					chatterParamData.setLimit(AppContext.limit);
					chatterParamData.setFeedId("");
					chatterParamData.setRecordId("");
					chatterParamData.setQueryType(AppContext.QueryType);
					page = 1;
					count = 0;
					skip = count * 10;
					chatterParamData.setSkip(skip);
					String a = Json.toJson(chatterParamData);
					new getChatterr().execute(a);
				}
			}
		});
		// 加载更多
		listview.setOnLoadListener(new OnLoadMoreListener() {
			@Override
			public void onLoadMore() {
				if (AppContext.QueryType.equals("mobileMe")) {
					chatterParamData = new ChatterParamData();
					chatterParamData.setUserId(UserManager.getManager()
							.getUser().userId);
					chatterParamData.setFeedSort(AppContext.feedSort);
					chatterParamData.setLimit(AppContext.limit);
					chatterParamData.setFeedId("");
					chatterParamData.setRecordId("");
					chatterParamData.setQueryType(AppContext.QueryType);
					skip = count * 10;
					chatterParamData.setSkip(skip);
					String a = Json.toJson(chatterParamData);
					new getChatterr().execute(a);
				}
			}
		});
		adapter.setOnItemtListener(new OnItemListener() {
			private DefaultHttpClient httpClient;

			@Override
			public void xihuan(int position, View v) {
				v.setClickable(false);
				weizhiid = total.get(position).getId();
				AppContext.iszan = weizhiid;
				weizhi = position;
				ispraised = !total.get(position).isIspraised();

				total.get(weizhi).setIspraised(ispraised);
				String num = total.get(weizhi).getPraisenum();
				if (num == null || num.equals("")) {
					praisenum = 0;
				} else {
					praisenum = Integer.valueOf(num);
				}
				if (ispraised) {
					total.get(weizhi).setPraisenum((praisenum + 1) + "");
				} else {
					int pnum = praisenum - 1;
					if (pnum == 0) {
						total.get(weizhi).setPraisenum("");
					} else {
						total.get(weizhi).setPraisenum((praisenum - 1) + "");
					}
				}

				v.setClickable(true);
				adapter.changeData(total);
				PraiseFeed praiseFeed = new PraiseFeed();
				praiseFeed.setFeedId(total.get(position).getId());
				if (ispraised) {
					praiseFeed.setLikeOrDislike("1");
				} else {
					praiseFeed.setLikeOrDislike("-1");
				}
				String xihuan = Json.toJson(praiseFeed);
				new xihuanTask(v).execute(xihuan);
			}

			@Override
			public void shoucang(int position) {
				weizhiid = total.get(position).getId();
				AppContext.shoucang = weizhiid;
				weizhi = position;
				FavoriteFeed favoriteFeed = new FavoriteFeed();
				favoriteFeed.setFeedId(weizhiid);
				isfavorited = !total.get(position).isIsfavorited();

				if (isfavorited) {
					total.get(weizhi).setIsfavorited(true);
				} else {
					total.get(weizhi).setIsfavorited(false);
				}
				adapter.changeData(total);

				if (isfavorited) {
					favoriteFeed.setFavoriteOrUnfavorite("1");
				} else {
					favoriteFeed.setFavoriteOrUnfavorite("-1");
				}
				String shoucang = Json.toJson(favoriteFeed);
				new shoucangTask().execute(shoucang);// 联网收藏
			}

			@Override
			public void pinglun(int position) {// 评论
				myChatter = total.get(position);
				Intent intent = new Intent(AboutMeActivty.this,
						DynamicActivity.class);
				intent.putExtra("myChatter", myChatter);
				startActivity(intent);
			}

			@Override
			public void shanchu(final int position) {
				if (!NetWork.detect(AboutMeActivty.this)) {
					
					if ("en".equals(mEns)) {
						Tools.showInfo(AboutMeActivty.this, "Please check the network~");
					}else{
						Tools.showInfo(AboutMeActivty.this, "亲，请检查网络~");
				}
					
					
					
					return;
				}
				if (total.get(position).getAuthorId()
						.equals(UserManager.getManager().getUser().userId)) {
					showDialogg(position);
				}
			}

			@Override
			public void downloadpic(int position) {
				LoadingUtils loading = new LoadingUtils(AboutMeActivty.this,
						total.get(position), position);
				loading.loadingFile();
			}

			@Override
			public void icon(int position) {
				weizhi = position;
				myChatter = total.get(position);
				Intent intent = new Intent(mContext,
						NewUserInfoActivity.class);
//				intent.putExtra(UserInfoActivity.KEY_USERID, t.authorId);
//				startActivity(intent);
//				Intent intent = new Intent(AboutMeActivty.this,
//						UserInfoActivity.class);
				intent.putExtra("userId", myChatter.authorId);
				startActivity(intent);
			}

			@Override
			public void nicheng(int position) {
				myChatter = total.get(position);
				Intent intent = new Intent(AboutMeActivty.this,
						UserInfoActivity.class);
				intent.putExtra("userId", myChatter.authorId);
				startActivity(intent);
			}

			@Override
			public void btntoupiao(int position) {
				myChatter = total.get(position);
				Intent intent = new Intent(AboutMeActivty.this,
						DynamicActivity.class);
				intent.putExtra("myChatter", myChatter);
				startActivity(intent);
			}

			@Override
			public void zhengti(int position) {
				myChatter = adapter.getItem(position);
				Intent intent = new Intent(AboutMeActivty.this,
						DynamicActivity.class);
				intent.putExtra("myChatter", myChatter);
				startActivity(intent);
			}
		});
	}

	class Ddialog {
		private TextView name;
	}

	class getChatterr extends AsyncTask<String, Void, String> {
		@Override
		protected String doInBackground(String... params) {
			String data = params[0];
			String result = service.getChatters01(data);
			return result;
		}

		@Override
		protected void onPostExecute(String result) {
			super.onPostExecute(result);
			msg = new MyChatterMessage();
			msg = MyChatterParser.getMyChatter(result);
			yiChang(result);
			if (!msg.isResult()) {
				handler.sendEmptyMessage(-3);
				return;
			}
			if (msg.getList().size() == 0 && total.size() == 0) {
				loadingview.setVisibility(View.GONE);
				frame.setVisibility(View.VISIBLE);
				no_wangluoo.setVisibility(View.VISIBLE);
				framelayout.setVisibility(View.GONE);
				return;
			}
			if (msg.getList().size() == 0) {
				handler.sendEmptyMessage(2);
				return;
			}

			if (page == 1) {
				total.clear();
			}
			for (int i = 0; i < msg.getList().size(); i++) {
				if (msg.getList().get(i).getFeedType().equals("V")) {
					List<Polls> list = msg.getList().get(i).getPolls();
					if (list != null) {
						for (int j = 0; j < list.size(); j++) {
							Polls p = list.get(j);
							String[] a = p.getOptionUsers();
							if (a.length > 0) {
								for (int k = 0; k < a.length; k++) {
									if (StringUtils.equals(UserManager
											.getManager().getUser().userId,
											a[k])) {
										msg.getList().get(i).setTpflag(true);
									}
								}
							}
						}
					}
				}
			}
			total.addAll(msg.getList());

			if (page == 1) {
				DbUtils db = DbUtils.create(AboutMeActivty.this, UserManager
						.getManager().getUser().userId + AppContext.QueryType);
				try {
					if (db.tableIsExist(MyChatter.class)) {
						db.deleteAll(MyChatter.class);
					}
					if (db.tableIsExist(Polls.class)) {
						db.deleteAll(Polls.class);
					}
					if (db.tableIsExist(OptionUser.class)) {
						db.deleteAll(OptionUser.class);
					}
					if (db.tableIsExist(FeedFile.class)) {
						db.deleteAll(FeedFile.class);
					}
					if (db.tableIsExist(Comments.class)) {
						db.deleteAll(Comments.class);
					}
					if (db.tableIsExist(CommentsFile.class)) {
						db.deleteAll(CommentsFile.class);
					}
					db.saveAll(total);
					for (int j = 0; j < total.size(); j++) {
						// 文件 或者图片
						try {
							List<FeedFile> flist = total.get(j).getFeedFile();
							if (flist != null) {
								for (int l = 0; l < flist.size(); l++) {
									FeedFile file = new FeedFile();
									file = flist.get(l);
									file.setParendId(total.get(j).getId());
									db.save(file);
								}
							}
						} catch (Exception e1) {
							Tools.handle(e1);
						}
						// 评论
						try {
							List<Comments> list = total.get(j).getComments();// 如果有评论,
							if (list != null) {
								for (int k = 0; k < list.size(); k++) {
									Comments comments = new Comments();
									comments = list.get(k);
									comments.setParendId(total.get(j).getId());// 把这条chatter记录
									CommentsFile commentsFile = comments
											.getCommentsFile();
									if (commentsFile != null) {
										commentsFile.setId(comments.getId());
										db.save(commentsFile);
									}
									db.save(comments);
								}
							}
						} catch (Exception e1) {
							Tools.handle(e1);
						}
						// 投票
						try {
							List<Polls> plist = total.get(j).getPolls();// 如果有投票
							if (plist != null) {
								for (int i = 0; i < plist.size(); i++) {
									Polls p = new Polls();
									p = plist.get(i);
									p.setParendId(total.get(j).getId());
									String[] e = p.getOptionUsers();
									if (e != null && e.length > 0) {
										for (int q = 0; q < e.length; q++) {
											OptionUser o = new OptionUser();
											o.setWho(e[q]);
											o.setParendId(total.get(j).getId());
											db.save(o);
										}
									}
									db.save(p);
								}
							}
						} catch (Exception e) {
							Tools.handle(e);
						}
					}
				} catch (DbException e) {
					Tools.handle(e);
				}

			}
			if (page == 1) {
				handler.sendEmptyMessage(0);
			} else {
				handler.sendEmptyMessage(1);
			}
		}

	}

	protected void showDialogg(final int position) {
		final Ddialog dd = new Ddialog();
		LayoutInflater inflater = getLayoutInflater();
		View layout = inflater.inflate(R.layout.define_deleted, null);
		dd.name = (TextView) layout.findViewById(R.id.titletitle);
		if ("en".equals(mEns)) {
			dd.name.setText("Are you sure you want to delete this post?");
		}else{
			dd.name.setText("确定删除这条微贴吗？");
	}
		
		final AlertDialog builder = new AlertDialog.Builder(this).create();
		builder.setView(layout);
		builder.show();
		Button cancle = (Button) layout.findViewById(R.id.quxiaocanle);
		cancle.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				builder.cancel();
			}
		});
		Button sure = (Button) layout.findViewById(R.id.quedingsure);
		sure.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (total.get(position).getAuthorId()
						.equals(UserManager.getManager().getUser().userId)) {
					RemoveMicroPost remove = new RemoveMicroPost();
					remove.setFeedId(total.get(position).getId());
					weizhiid = total.get(position).getId();
					// 联网删帖
					String json = Json.toJson(remove);
					new MyTask().execute(json);
					// list里删除，
					total.remove(position);
					adapter.changeData(total);
					builder.cancel();
				}
			}
		});

	}

	class MyTask extends AsyncTask<String, Void, String> {
		@Override
		protected String doInBackground(String... params) {
			String data = params[0];
			String json;
			List<NameValuePair> pairs = new ArrayList<NameValuePair>();
			pairs.add(new BasicNameValuePair("serviceName", "removeMicroPost"));
			pairs.add(new BasicNameValuePair("data", data));
			pairs.add(new BasicNameValuePair("binding", AppContext.binding));
			String url = UrlTools.url + UrlTools.url_path;
			json = NetWork.post(url, pairs);
			return json;
		}
	}

	Handler handler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			String s1 = "查询异常";
			String s2 = "连接超时，请稍后重试";
			String s3 = "查询失败";
			String s4 = "数据加载完成";
			if ("en".equals(mEns)) {
				 s1 = "Query exception";
				 s2 = "The connection timed out. Please try again later";
				 s3 = "Query failed";
				 s4 = "The data is loaded";
			}else{
				 s1 = "查询异常";
				 s2 = "连接超时，请稍后重试";
				 s3 = "查询失败";
				 s4 = "数据加载完成";
		}
			try {
				switch (msg.what) {
				case 1:
					adapter.changeData(total);
					page++;
					count++;
					break;
				case 0:
					adapter.changeData(total);
					listview.setAdapter(adapter);
					page++;
					count++;
					break;
				case -1:
					Tools.showInfo(AboutMeActivty.this, s1);
					break;
				case -2:
					Tools.showInfo(AboutMeActivty.this, s2);
					break;
				case -3:
					Tools.showInfo(AboutMeActivty.this,s3);
					break;

				case 2:
					Tools.showInfo(AboutMeActivty.this, s4);
					break;
				default:
					listview.onLoadMoreComplete();
					listview.onRefreshComplete();
					loadingview.setVisibility(View.GONE);
					break;
				}
				listview.onLoadMoreComplete();
				listview.onRefreshComplete();
				listview.setCanRefresh(true);
				listview.setCanLoadMore(true);
				listview.setAutoLoadMore(true);
				loadingview.setVisibility(View.GONE);
				super.handleMessage(msg);
			} catch (Exception e) {
				Tools.handle(e);
			}
		}
	};

	public void yiChang(String result) {
		if (result == null || result.equals("NetworkError")) {
			handler.sendEmptyMessage(-1);
			if (total.size() == 0) {
				framelayout.setVisibility(View.GONE);
				frame.setVisibility(View.VISIBLE);
				no_wangluoo.setVisibility(View.VISIBLE);
			}
			return;
		}
		if (result.equals("outTime")) {
			handler.sendEmptyMessage(-2);
			return;
		}
		String code = ReturnCodeParser.getReturnCode(result);
		if (code.equals("-2")) {
			if ("en".equals(mEns)) {
				Tools.showInfo(AboutMeActivty.this, "Landing time, please re-landing ");
			}else{
				Tools.showInfo(AboutMeActivty.this, "登陆超时,请重新登陆");
		}
			
			Intent intent = new Intent(this, LoginNewActivity.class);
			startActivity(intent);
			AboutMeActivty.this.finish();
		}
	}

	class xihuanTask extends AsyncTask<String, Void, String> {
		private RelativeLayout v;

		public xihuanTask(View v) {
			this.v = (RelativeLayout) v;
		}

		@Override
		protected String doInBackground(String... params) {
			String xihuan = params[0];
			List<NameValuePair> pairs = new ArrayList<NameValuePair>();
			pairs.add(new BasicNameValuePair("serviceName", "praiseFeed"));
			pairs.add(new BasicNameValuePair("data", xihuan));
			pairs.add(new BasicNameValuePair("binding", AppContext.binding));
			String url = UrlTools.url + UrlTools.url_path;
			String result = NetWork.post(url, pairs);
			return result;
		}

		@Override
		protected void onPostExecute(String result) {
			super.onPostExecute(result);
			try {
				yiChang(result);
				PraiseFeedInfo info = HandleParser.xihuan(result);
				boolean flag = info.isResult();
				if (flag) {
				} else {
				}
			} catch (Exception e) {
				e.printStackTrace();
				Tools.handle(e);
			}
		}
	}

	class toupiaoTask extends AsyncTask<String, Void, String> {

		@Override
		protected String doInBackground(String... arg0) {
			String toupiao = arg0[0];
			List<NameValuePair> pairs = new ArrayList<NameValuePair>();
			pairs.add(new BasicNameValuePair("serviceName", "voteMicroPost"));
			pairs.add(new BasicNameValuePair("data", toupiao));
			pairs.add(new BasicNameValuePair("binding", AppContext.binding));
			String url = UrlTools.url + UrlTools.url_path;
			String result = NetWork.post(url, pairs);
			return result;
		}

		@Override
		protected void onPostExecute(String result) {
			super.onPostExecute(result);
			try {

			} catch (Exception e) {
				Tools.handle(e);
			}

		}
	}

	class shoucangTask extends AsyncTask<String, Void, String> {
		@Override
		protected String doInBackground(String... params) {
			String shoucang = params[0];
			List<NameValuePair> pairs = new ArrayList<NameValuePair>();
			pairs.add(new BasicNameValuePair("serviceName", "favoriteFeed"));
			pairs.add(new BasicNameValuePair("data", shoucang));
			pairs.add(new BasicNameValuePair("binding", AppContext.binding));
			String url = UrlTools.url + UrlTools.url_path;
			String result = NetWork.post(url, pairs);
			return result;
		}

		@Override
		protected void onPostExecute(String result) {
			super.onPostExecute(result);
			try {
				yiChang(result);
				PraiseFeedInfo info = HandleParser.xihuan(result);
				boolean flag = info.isResult();
				if (flag) {

				} else {
					if ("en".equals(mEns)) {
						Tools.showInfo(AboutMeActivty.this, "收藏失败");
					}else{
						Tools.showInfo(AboutMeActivty.this, "收藏失败");
				}
					
				}
			} catch (Exception e) {
				e.printStackTrace();
				Tools.handle(e);
			}
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.re:
			AboutMeActivty.this.finish();
			break;
		default:
			break;
		}
	}

	class Receiver extends BroadcastReceiver {
		@Override
		public void onReceive(Context context, Intent intent) {
			try {
				String action = intent.getAction();
				if (action.equals(AppContext.INDEXADAPTER_SHUAXIN)) {
					if (AppContext.QueryType.equals("me")) {
						chatterParamData = new ChatterParamData();
						chatterParamData.setUserId(UserManager.getManager()
								.getUser().userId);
						chatterParamData.setFeedSort(AppContext.feedSort);
						chatterParamData.setLimit(AppContext.limit);
						chatterParamData.setFeedId("");
						chatterParamData.setRecordId("");
						chatterParamData.setQueryType(AppContext.QueryType);
						count = 0;
						skip = count * 10;
						chatterParamData.setSkip(skip);
						String a = Json.toJson(chatterParamData);
						new getChatterr().execute(a);
					}

				}
			} catch (Exception e) {
				Tools.handle(e);
			}
		}
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		unregisterReceiver(receiver);
	}

}
